angular.module("ThumbnailDirectives", [])

	.directive("agencelogo", function () {
      return {
        restrict: 'AE',
        replace: true,
        scope : {thId:'@', thNom:'@', thLibelle:'@' },
        template: '<img src="/img/galerie/agence__{{agenceId}}__/{{agenceNom}}" title="Agence {{agenceLibelle}}" alt="Logo de l\'agence {{agenceLibelle}}">',
        link: function(scope, elem, attrs) {

          scope.$watch("thId", function( newValue, oldValue ) {
              
              if( newValue != null && newValue != "") {

                scope.agenceId = newValue;
                scope.agenceLibelle = scope.thLibelle;

                var extensionFichier = scope.thNom.split('.').pop();
                var fichierSansExtension = scope.thNom.replace(/\.[^/.]+$/, "");

                scope.agenceNom = fichierSansExtension + "-min" + "." + extensionFichier;
              }

          });

        }
      };
   })

   .directive("sejouraccueil", function () {
    return {
        restrict: 'AE',
        replace: true,
        scope : {thId:'@', thNom:'@', thLibelle:'@' },
        template: '<img class="img-responsive-height" src="/img/galerie/sejour__{{sejourId}}__/{{sejourImageNom}}" alt="Image séjour {{sejourLibelle}}" title="Séjour {{sejourLibelle}}">',
        link: function(scope, elem, attrs) {

          scope.$watch("thId", function( newValue, oldValue ) {
              
              if( newValue != null && newValue != "") {

                scope.sejourId = newValue;
                scope.sejourLibelle = scope.thLibelle;

                var extensionFichier = scope.thNom.split('.').pop();
                var fichierSansExtension = scope.thNom.replace(/\.[^/.]+$/, "");

                scope.sejourImageNom = fichierSansExtension + "-main" + "." + extensionFichier;
              }

          });

        }
      };
   })

   .directive("sejourgalerie", function () {
    return {
        restrict: 'AE',
        replace: true,
        scope : {thId:'@', thNom:'@', thLibelle:'@' },
        template: '<img src="/img/galerie/sejour__{{sejourId}}__/{{sejourImageNom}}" alt="Image : {{sejourLibelle}}" title="Image : {{sejourLibelle}}">',
        link: function(scope, elem, attrs) {

          scope.$watch("thId", function( newValue, oldValue ) {
              
              if( newValue != null && newValue != "") {

                scope.sejourId = newValue;
                scope.sejourLibelle = scope.thLibelle;

                var extensionFichier = scope.thNom.split('.').pop();
                var fichierSansExtension = scope.thNom.replace(/\.[^/.]+$/, "");

                scope.sejourImageNom = fichierSansExtension + "-min" + "." + extensionFichier;
              }

          });

        }
      };
   })

   .directive("galeriemin", function () {
    return {
        restrict: 'A',
        scope : {thSejourid:'@', thSejourimage: '@'},
        link: function(scope, elem, attrs) {

          scope.sejourId = scope.thSejourid;

          var extensionFichier = scope.thSejourimage.split('.').pop();
          var fichierSansExtension = scope.thSejourimage.replace(/\.[^/.]+$/, "");

          scope.sejourImage = fichierSansExtension + "-min" + "." + extensionFichier;

          attrs.$set('src', '/img/galerie/sejour__'+ scope.sejourId +'__/' + scope.sejourImage);

        }
      };
   })

   .directive("galeriethumbmin", function () {
		return {
        restrict: 'A',
        scope : {thSejourid:'@', thSejourimage: '@'},
        link: function(scope, elem, attrs) {
          scope.$watch("thSejourimage", function( newValue, oldValue ) {

            scope.sejourId = scope.thSejourid;

            var extensionFichier = newValue.split('.').pop();
            var fichierSansExtension = newValue.replace(/\.[^/.]+$/, "");

            scope.sejourImage = fichierSansExtension + "-thumb" + "." + extensionFichier;

            attrs.$set('src', '/img/galerie/sejour__'+ scope.sejourId +'__/' + scope.sejourImage);

          });
        }
      };
	 })
